package com.example.springframeworklearning.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.DefaultMessageCodesResolver;
import org.springframework.validation.MessageCodesResolver;

/**
 * 用于将校验失败的输出 org.springframework.validation.Errors 中的 errorCode 翻译为 错误提示
 * 参考：https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#validator
 *
 * @author luo
 * @since 2022/9/21 16:42
 */
@Configuration
public class MessageCodesResolverConfig {


    @Bean
    public MessageCodesResolver messageCodesResolver() {

        DefaultMessageCodesResolver result = new DefaultMessageCodesResolver();

        result.setMessageCodeFormatter(DefaultMessageCodesResolver.Format.PREFIX_ERROR_CODE);

        return result;
    }
}
